n = int(input())
a = []
b = []
cost = [[] for _ in range(10)]
k = n // 10
for _ in range(n):
    a, b = map(int, input().split())
    cost[a].append(b) 
ans = 0

for i in range(10):
    cost_i = sorted(cost[i])
    ans += sum(cost_i[:-k])

print(ans)
